/* FILE : ime.c */

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#include <stdio.h>
#include <unistd.h>
#include <gtk/gtk.h>
#include <standard_im.h>

#include "ime.h"
#include "im.h"
#include "imm.h"
#include "ui.h"

static int coox = 0;
static int cooy = 0;

static void update_display(char *);
static void process_ime_event(IM1Event *imev);

void
ime_receive_handler(void *buf, size_t buf_size)
{
#if DEBUG
	fprintf(stderr, "DEFAULT UI : ime receive handler\n");
#endif
	IM1Event *imev = (IM1Event *)(buf + sizeof(IMECommand) + sizeof(int));
	int *ime_command = (int *)buf;

#if DEBUG
	fprintf(stderr, "DEFAULT UI : receive command %d\n", *ime_command);
#endif

	switch (*ime_command) {
	case IME_IMM_VERSION:
		break;
	case IME_INITIALIZE:
		break;
	case IME_FINALIZE:
		break;
	case IME_HIDE:
		break;
	case IME_UPDATE_DISPLAY:
		update_display((char *)(buf + sizeof(int)*2));
		break;
	case IME_UPDATE_SCREEN:
		break;
	case IME_UPDATE_SPOT_LOCATION:
		break;
	case IME_UPDATE_TRIGGER_PROPERTY:
		break;
	case IME_PROCESS_IME_EVENT:
		process_ime_event(imev);
		break;
	}

}

static void
update_display(char *s)
{
#if DEBUG
	fprintf(stderr, "DEFAULT UI : update display\n");
#endif
	coox = *(int *)s;
	cooy = *(int *)(s + sizeof(int));
}

static void
process_ime_event(IM1Event *imev)
{
	LookupData *lu_data;
#if DEBUG
	fprintf(stderr, "DEFAUTLT UI : process ime event\n");
#endif
	switch (imev->type) {
	case IM1_CANDIDATE:
#if DEBUG
		fprintf(stderr, "DEFAULT UI : IM1_CANDIDATE Event\n");
		fprintf(stderr, "DEFAULT UI : number of candidates : %d\n", imev->num);
		fprintf(stderr, "DEFAULT UI : candidate0 : %s\n", imev->string0);
		fprintf(stderr, "DEFAULT UI : candidate1 : %s\n", imev->string1);
#endif
		lu_data = ui_parse_lookup_values(imev);
		ui_draw_lu_vert(coox, cooy, lu_data);
		break;
	case IM1_PREEDIT:
#if DEBUG
		fprintf(stderr, "DEFAULT UI : IM1_PREEDIT Event\n");
#endif
		break;
	}
	return;
}


